package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

/*
 * hiddens控件组
 */
public class Hiddens extends NokaTag{
	private static final long serialVersionUID = 4286292427104765104L;
	private String id = null;//控件id
	private String json = null;//控件json数据 [{id:'',name:'',value:''},{}]
	private String isdebug = null;
	public int doStartTag()throws JspException{
		JspWriter jspOut = pageContext.getOut();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(potjs(request));//加载Prototype
		stringBuilder.append(hiddensJs(request));//加载hiddensJs
		stringBuilder.append("<div id=\""+id+"\"></div>");
		stringBuilder.append("<script type=\"text/javascript\">");
		stringBuilder.append("Event.observe(document, 'dom:loaded', function() {");
		stringBuilder.append("var cfghid"+getId()+" = {id:'"+getId()+"',"+("true".equalsIgnoreCase(isdebug)?"debug:true,":"")+"json:"+(json==null?"[]":json)+"};");
		stringBuilder.append("var nhid"+getId()+" = new nhiddens(cfghid"+getId()+");");
		stringBuilder.append("nhid"+getId()+".show();");
		stringBuilder.append("});");
		stringBuilder.append("</script>");
		try {
			jspOut.write(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getJson() {
		return json;
	}
	public void setJson(String json) {
		this.json = json;
	}
	public String getIsdebug() {
		return isdebug;
	}
	public void setIsdebug(String isdebug) {
		this.isdebug = isdebug;
	}
}
